/**
 * 数组转置
 */

class Matrix {
    arr = [] //二维数组
    constructor(arr) {
        this.arr = arr
    }

    // 获取二维数组1/2维数组长度
    get rowNum() {
        return this.arr.length
    }

    get colNum() {
        return this.arr[0].length
    }

    // 遍历 拿到二维数组的每一个元素 以及行列
    each(cb) {
        for (let c = 0; c < this.colNum; c++) {
            for (let r = 0; r < this.rowNum; r++) {
                const item = this.arr[r][c]
                cb(item, r, c)
            }
        }
    }

    // 二维数组的转置
    transpose() {
        const newArr = []
        for (let c = 0; c < this.colNum; c++) {
            newArr[c] = []
            for (let r = 0; r < this.rowNum; r++) {
                newArr[c][r] = this.arr[r][c]
            }
        }
        return newArr
    }
}
export {
    Matrix
}